package com.ecomemerce.app.takeaway

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.ecomemerce.app.TopNavBar
import com.ecomemerce.app.comment.widgets.CategoryGrid
 import com.ecomemerce.app.comment.widgets.ProductsPreferred

import com.ecomemerce.app.comment.widgets.RecommendShop
import com.ecomemerce.app.comment.widgets.BannerSection
import com.ecomemerce.app.comment.widgets.ProductList
import com.ecomemerce.app.comment.widgets.SearchBar
import com.ecomemerce.app.getComponentOrderFromServer

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun HomeScreen() {
    val componentOrder = remember { getComponentOrderFromServer() }


    LazyColumn (
        modifier = Modifier
            .fillMaxWidth()
            .padding(8.dp)
    ) {

        componentOrder.forEach { component ->
            when (component) {
                "search" -> item { SearchBar() }
                "banner" -> item {BannerSection()}
                "category" -> item {CategoryGrid()}
                "products" -> item {ProductList()}
                "productsPreferred"-> item {ProductsPreferred()}
                "recommendShop" -> item {RecommendShop()}
                "bottomPage" -> {
                    stickyHeader {
                        TopNavBar()
                    }
                    items(20) { index ->
                        RecommendShop()
                    }
                }
            }
        }
    }
}

